<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/8/13
 * Time: 16:52
 */

namespace app\api\model;


class Theme extends BaseModel
{
    /**
     * 对象隐藏字段
     * @var array
     */
    protected $hidden=["topic_img_id", "delete_time", "head_img_id", "update_time"];
    /**
     * 与图片表一对一关联
     * @return \think\model\relation\BelongsTo
     */
    public function  topicImg(){
        return $this->belongsTo('Image','topic_img_id','id');
    }
    /**
     * 与图片表一对一关联
     * @return \think\model\relation\BelongsTo
     */
    public function headImg(){
        return $this->belongsTo('Image','head_img_id','id');
    }

    /**
     * 与产品表多对多关联
     * @return \think\model\relation\BelongsToMany
     */
    public function products(){
        return $this->belongsToMany('Product','theme_product','product_id','theme_id');
    }
    /**
     * 获取Theme接口信息
     * @param array $ids
     * @return \think\response\Json
     */
    public static function  getThemeByIDs($ids){
        $result =  self::with('topicImg,headImg')->select($ids);
        return  $result;
    }
    /**
     * 获取theme详细信息
     * @param $id
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static  function getComplexByID($id){
        $result = self::with('products,topicImg,headImg')->find($id);
        return $result;
    }
}